package com.tuliyou.mapper;

import com.tuliyou.dto.UniMajorEnrollmentDTO;
import com.tuliyou.entity.Major;
import com.tuliyou.entity.UniMajorEnrollment;
import com.tuliyou.entity.University;
import com.tuliyou.entity.User;
import com.tuliyou.request.UpdateUserRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AdminMapper {
    List<User> getUsers(String username, String userType, Integer isDeleted);

    int updateUser(@Param("id") Integer id, @Param("updateUserRequest") UpdateUserRequest updateUserRequest);

    @Select("select * from users where id = #{id}")
    User getById(Integer id);





    List<University> getUniversities(String name, Integer uniYear, String province, String city, String level, String attribute, Integer isDeleted);

    @Insert("insert into universities " +
            "value (#{universityCode},#{name},#{uniYear}," +
            "#{province},#{city},#{attribute}," +
            "#{level},#{isUndergraduate},#{description}," +
            "#{officialWebsite},#{isDeleted})")
    int insertUniversity(University university);

    int updateUniversity(@Param("universityCode") String universityCode, @Param("uniYear") Integer uniYear, @Param("university") University university);





    List<Major> getMajors(String majorCode, String majorName, String parentCode, Integer level, String degreeType, String years, Integer isDeleted);

    @Insert("insert into majors " +
            "value (#{majorCode},#{majorName},#{parentCode}," +
            "#{level},#{degreeType},#{years}," +
            "#{coreCourses},#{employmentDir},#{isDeleted})")
    int insertMajor(Major major);

    int updateMajor(@Param("majorCode") String majorCode, @Param("major") Major major);





    List<UniMajorEnrollment> getUniMajorEnrollments(String universityCode, String majorName, Integer enrollYear, String province, String examType, String educationLevel, Integer isDeleted);

    @Insert("insert into uni_major_enrollments (university_code, major_name, enroll_year, province, exam_type, education_level, min_score, min_rank, plan_count, actual_count, description, is_deleted)" +
            "value (#{universityCode},#{majorName},#{enrollYear},#{province},#{examType},#{educationLevel},#{minScore},#{minRank},#{planCount},#{actualCount},#{description},#{isDeleted})")
    int insertUniMajorEnrollment(UniMajorEnrollmentDTO uniMajorEnrollmentDTO);

    @Select("select * from uni_major_enrollments where id = (select max(id) from uni_major_enrollments)")
    UniMajorEnrollment getNewUniMajorEnrollment();

    int updateUniMajorEnrollment(@Param("id") Integer id, @Param("dto")UniMajorEnrollmentDTO uniMajorEnrollmentDTO);

    @Select("select * from uni_major_enrollments where id = #{id}")
    UniMajorEnrollment getUniMajorEnrollmentById(Integer id);
}
